//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    userInfo: {},
    user:null,

  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.onLoad()
  },
  onShow: function(){
    var that = this
    this.setData({
      user:app.globalData.user,
    })
    console.log(this.data.user)

   
  },
  onLoad: function () {
    wx.getSetting({
      success(res) {
        console.log(res)
        if (!res.authSetting["scope.userInfo"]) {
          wx.openSetting({
            complete: (res) => {
              wx.showToast({
                title: '请打开获得用户信息权限',
                icon:"none"
              })
            },
          })
        }
      }
    })

  },
  logout(){
    if (app.globalData.userId == null) {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      })
      return;
    }
    app.globalData.user=null
    app.globalData.userId=null
    app.globalData.role=null

    this.setData({
      user:null,
      userInfo:{}
    })

    this.onLoad()
  }

})
